package com.redispro.interceptors;

import com.redispro.dto.UserDTO;
import com.redispro.utils.UserHolder;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.*;

/**
 * @Auther: 李 力
 * @Date: 2024/11/22
 * @Description: com.redispro.interceptors
 * @version: 1.0
 */
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        UserDTO user = UserHolder.getUser();
        if (user == null) {
            response.setStatus(401);
            return false;
        }
        return true;
    }
}
